package android.framework.util;

import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.database.Cursor;
import android.framework.App;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Util {
	public static long currentClickPlayTime;
	public static long currentClickTime;
	public static long lastClickPlayTime;
	public static long lastClickTime = 0L;

	static {
		currentClickTime = 0L;
		lastClickPlayTime = 0L;
		currentClickPlayTime = 0L;
	}

	public static String MD5Helper(String paramString) {
		StringBuilder localStringBuilder = new StringBuilder();
		;
		int i;
		try {
			MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
			localMessageDigest.reset();
			localMessageDigest.update(paramString.getBytes("UTF-8"));
			byte[] arrayOfByte = localMessageDigest.digest();
			i = 0;
			if (i >= arrayOfByte.length)
				return "";
			if (Integer.toHexString(0xFF & arrayOfByte[i]).length() == 1) {
				localStringBuilder.append("0").append(
						Integer.toHexString(0xFF & arrayOfByte[i]));
			}
			localStringBuilder.append(Integer
					.toHexString(0xFF & arrayOfByte[i]));
		} catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
			localNoSuchAlgorithmException.printStackTrace();
			throw new RuntimeException("no device Id");
		} catch (UnsupportedEncodingException localUnsupportedEncodingException) {
			localUnsupportedEncodingException.printStackTrace();
		}
		return localStringBuilder.toString();
	}

	public static boolean checkBrowser(Context paramContext, String paramString) {
		if ((paramString == null) || ("".equals(paramString)))
			return false;
		else {
			try {
				paramContext.getPackageManager().getApplicationInfo(
						paramString, 8192);
				return true;
			} catch (PackageManager.NameNotFoundException localNameNotFoundException) {

			}
		}
		return false;
	}

	public static boolean checkClickEvent() {
		return checkClickEvent(1000L);
	}

	public static boolean checkClickEvent(long paramLong) {
		currentClickTime = System.currentTimeMillis();
		if (currentClickTime - lastClickTime > paramLong) {
			return true;
		}
		return false;
	}

	public static boolean checkClickPlay() {
		currentClickPlayTime = System.currentTimeMillis();
		if (currentClickPlayTime - lastClickPlayTime > 2000L)
			return true;
		return false;
	}

	public static void checkIpValid_ForDownload(Context paramContext,
			String paramString, IpValidListener paramIpValidListener) {
	}

	public static void checkIpValid_ForPlay(Context paramContext,
			String paramString, boolean paramBoolean,
			IpValidListener paramIpValidListener) {
	}

	public static boolean checkLoginUserString(String paramString) {
		return true;
	}

	public static void closeApp(Context paramContext) {
		try {
			App.getInstance().exitApp();
			NotificationManager localNotificationManager = (NotificationManager) App
					.getInstance().getSystemService("notification");
			localNotificationManager.cancel(1);
			localNotificationManager.cancel(112233);
			android.os.Process.killProcess(android.os.Process.myPid());
			System.exit(0);
		} catch (Exception localException) {
		}
	}

	public static void closeCursor(Cursor paramCursor) {
		if ((paramCursor == null) || (paramCursor.isClosed()))
			return;
		paramCursor.close();
	}

	public static int compareTime(String paramString1, String paramString2) {
		SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("mm:ss");
		int i;
		try {
			int j = localSimpleDateFormat.parse(paramString1).compareTo(
					localSimpleDateFormat.parse(paramString2));
			i = j;
		} catch (ParseException localParseException) {
			localParseException.printStackTrace();
			i = 0;
		}
		return i;
	}

	public static boolean emailFormats(String paramString) {
		if (paramString == null)
			return false;
		else {
			if (!Pattern
					.compile(
							"^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$")
					.matcher(paramString).matches())
				return true;
		}
		return false;
	}

	public static String formatDouble(double paramDouble, int paramInt) {
		DecimalFormat localDecimalFormat = new DecimalFormat();
		String str = "��";
		if (paramInt == 1) {
			localDecimalFormat = new DecimalFormat("#0.0");
			str += localDecimalFormat.format(paramDouble);
		} else if (paramInt > 2) {
			DecimalFormat localDecimalFormat2 = new DecimalFormat("#0.00");
			str += localDecimalFormat2.format(paramDouble);
		}
		return str;
	}

	public static String generateDeviceId(Context paramContext) {
		return MD5Helper(getIMEI(paramContext) + getIMSI(paramContext)
				+ getDeviceName() + getBrandName()
				+ getMacAddress(paramContext));
	}

	private static String generate_DeviceId(Context paramContext) {
		return MD5Helper(getIMEI(paramContext) + getDeviceName()
				+ getBrandName() + getMacAddress(paramContext));
	}

	public static String getBookTime(String paramString) {
		SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm");
		Date localDate1;
		try {
			Date localDate2 = localSimpleDateFormat.parse(paramString);
			Calendar localCalendar = Calendar.getInstance();
			localCalendar.setTime(localDate2);
			return new SimpleDateFormat("HH:mm")
					.format(localCalendar.getTime());
		} catch (ParseException localParseException) {
			localParseException.printStackTrace();
			localDate1 = new Date();
		}
		return localSimpleDateFormat.format(localDate1);
	}

	public static String getBrandName() {
		String str = Build.BRAND;
		if ((str == null) || (str.length() <= 0))
			str = "";
		return str;
	}

	public static int getClientVersionCode(Context paramContext) {
		int i = 0;
		if (paramContext == null)
			paramContext = App.getInstance();
		try {
			i = paramContext.getPackageManager().getPackageInfo(
					paramContext.getPackageName(), 0).versionCode;
		} catch (PackageManager.NameNotFoundException localNameNotFoundException) {
			localNameNotFoundException.printStackTrace();
		}
		return i;
	}

	public static String getClientVersionName(Context paramContext) {
		String str;
		if (paramContext == null)
			paramContext = App.getInstance();
		try {
			str = paramContext.getPackageManager().getPackageInfo(
					paramContext.getPackageName(), 0).versionName;
		} catch (PackageManager.NameNotFoundException localNameNotFoundException) {
			localNameNotFoundException.printStackTrace();
			str = "";
		}
		return str;
	}

	public static String getDensity(Context paramContext) {
		return String
				.valueOf(paramContext.getResources().getDisplayMetrics().density);
	}

	public static String getDeviceId(Context paramContext) {
		return "";
	}

	public static String getDeviceName() {
		String str = Build.MODEL;
		if ((str == null) || (str.length() <= 0))
			str = "";
		return str;
	}

	public static int getDisplayWidth(Context paramContext) {
		DisplayMetrics localDisplayMetrics = paramContext.getResources()
				.getDisplayMetrics();
		int i = localDisplayMetrics.widthPixels;
		int j = localDisplayMetrics.heightPixels;
		return i;
	}

	public static String getG(long paramLong) {
		double d = paramLong / 1073741824.0D;
		return new DecimalFormat("0.00").format(d);
	}

	public static String getIMEI(Context paramContext) {
		String str = ((TelephonyManager) App.getInstance()
				.getSystemService("phone")).getDeviceId();
		return str;
	}

	public static String getIMSI(Context paramContext) {
		String str = ((TelephonyManager) App.getInstance()
				.getSystemService("phone")).getSubscriberId();
		do {
			str.replace(" ", "");
		} while (!TextUtils.isEmpty(str));
		return str;
	}

	public static String getMacAddress(Context paramContext) {
		WifiInfo localWifiInfo = ((WifiManager) paramContext
				.getSystemService("wifi")).getConnectionInfo();
		String str = "";
		if (localWifiInfo != null) {
			str = localWifiInfo.getMacAddress();
		}
		return str;
	}

	public static int getNumCores() {
		int i;
		try {
			i = new File("/sys/devices/system/cpu/")
					.listFiles(new FileFilter() {
						public boolean accept(File paramFile) {
							if (Pattern.matches("cpu[0-9]", paramFile.getName()))
								return true;
							return false;
						}
					}).length;
			return i;
		} catch (Exception localException) {
			i = 1;
		}
		return i;
	}

	public static String getNumberTime(long paramLong) {
		long l1 = paramLong % 60L;
		long l2 = paramLong / 60L % 60L;
		long l3 = paramLong / 3600L;
		Formatter localFormatter = new Formatter(null, Locale.getDefault());
		Object[] arrayOfObject = new Object[3];
		arrayOfObject[0] = Long.valueOf(l3);
		arrayOfObject[1] = Long.valueOf(l2);
		arrayOfObject[2] = Long.valueOf(l1);
		return localFormatter.format("%02d:%02d:%02d", arrayOfObject)
				.toString();
	}

	public static String getOSVersionName() {
		return Build.VERSION.RELEASE;
	}

	public static String getResolution(Context paramContext) {
		DisplayMetrics localDisplayMetrics = paramContext.getResources()
				.getDisplayMetrics();
		return localDisplayMetrics.widthPixels + "*"
				+ localDisplayMetrics.heightPixels;
	}

	public static String getSDK() {
		return Build.VERSION.SDK;
	}

	public static String getSystemName() {
		return "android";
	}

	public static long getTimeLong(String paramString) {
		SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm");
		Date localDate1;
		try {
			Date localDate2 = localSimpleDateFormat.parse(paramString);
			localDate1 = localDate2;
		} catch (ParseException localParseException) {
			localParseException.printStackTrace();
			localDate1 = new Date();
		}
		return localDate1.getTime();
	}

	public static String getUUID(Context paramContext) {
		return generateDeviceId(paramContext) + "_"
				+ System.currentTimeMillis();
	}

	public static String getUserAgent() {
		StringBuilder localStringBuilder = new StringBuilder(Build.MODEL);
		if (localStringBuilder.toString().startsWith("\""))
			localStringBuilder.deleteCharAt(0);
		if (localStringBuilder.toString().endsWith("\""))
			localStringBuilder.deleteCharAt(-1 + localStringBuilder.length());
		return localStringBuilder.toString();
	}

	public static int[] getWeekDays(int paramInt) {
		int[] arrayOfInt = new int[7];
		for (int i = 0; i < 7; ++i)
			arrayOfInt[i] = (paramInt + i);
		return arrayOfInt;
	}

	public static void hasDownloadFile(File paramFile,
			hasDownloadFileListener paramhasDownloadFileListener) {
	}

	public static boolean hasSDCard() {
		if (Environment.getExternalStorageState().equals("mounted"))
			return true;
		return false;
	}

	public static boolean isMobileNO(String paramString) {
		if (paramString == null)
			return false;
		boolean bool = false;
		bool = Pattern.compile("^(1)\\d{10}$").matcher(paramString).matches();
		return bool;
	}

	public static boolean isNetAvailableForPlay(Context paramContext) {
		if (NetWorkTypeUtils.getAvailableNetWorkInfo(paramContext) == null)

			return false;
		return true;
	}

	public static boolean passwordFormat(String paramString) {
		if (paramString == null)
			return false;
		if (!Pattern.compile("^[a-zA-Z0-9_]{6,16}$").matcher(paramString)
				.matches())
			return false;
		return true;
	}

	public static void ping() {
		new Thread() {
			public void run() {
				try {
					BufferedReader localBufferedReader = new BufferedReader(
							new InputStreamReader(Runtime.getRuntime()
									.exec("ping -c 100 -s 65500 www.sina.com")
									.getInputStream()));
					String str1;
					do {
						str1 = localBufferedReader.readLine();
						if (str1 == null)
							return;
						System.out.println("str  == " + str1);
						if (!str1.contains("packet loss"))
							continue;
						int k = str1.indexOf("received");
						int l = str1.indexOf("%");
						str1.substring(k + 10, l + 1);
					} while (!str1.contains("avg"));
					int i = str1.indexOf("/", 20);
					int j = str1.indexOf(".", i);
					String str2 = str1.substring(i + 1, j);
					new StringBuilder().append(str2).append("ms").toString();
				} catch (Exception localException) {
					localException.printStackTrace();
				}
			}
		}.start();
	}

	public static void retrievePwdBySMS(Context paramContext) {
		Intent localIntent = new Intent("android.intent.action.SENDTO",
				Uri.parse("smsto:10690159292121"));
		localIntent.putExtra("sms_body", "");
		paramContext.startActivity(localIntent);
	}

	public static void setBackgroundResource(Context paramContext,
			View paramView, int paramInt) {
		TypedValue localTypedValue = new TypedValue();
		localTypedValue.density = App.getInstance().getResources()
				.getDisplayMetrics().densityDpi;
		paramView.setBackgroundDrawable(Drawable.createFromResourceStream(
				paramContext.getResources(), localTypedValue, paramContext
						.getResources().openRawResource(paramInt), null));
	}

	public static void setImageResource(Context paramContext,
			ImageView paramImageView, int paramInt) {
		TypedValue localTypedValue = new TypedValue();
		localTypedValue.density = App.getInstance().getResources()
				.getDisplayMetrics().densityDpi;
		paramImageView.setImageDrawable(Drawable.createFromResourceStream(
				paramContext.getResources(), localTypedValue, paramContext
						.getResources().openRawResource(paramInt), null));
	}

	public static String stringForTime(int paramInt) {
		StringBuilder localStringBuilder = new StringBuilder();
		Formatter localFormatter = new Formatter(localStringBuilder,
				Locale.getDefault());
		int i = paramInt / 1000;
		int j = i % 60;
		int k = i / 60 % 60;
		int l = i / 3600;
		localStringBuilder.setLength(0);
		Object[] arrayOfObject = new Object[3];
		arrayOfObject[0] = Integer.valueOf(l);
		arrayOfObject[1] = Integer.valueOf(k);
		arrayOfObject[2] = Integer.valueOf(j);
		return localFormatter.format("%02d:%02d:%02d", arrayOfObject)
				.toString();
	}

	public static String timeString(long paramLong) {
		return new SimpleDateFormat("yyyy-MM-dd").format(new Date(paramLong));
	}

	public static String timeString(String paramString) {
		String str1 = null;
		if ((paramString != null) && (!"".equals(paramString.trim()))) {
			try {
				str1 = timeString(Long.parseLong(paramString));
			} catch (Exception localException) {
				str1 = "";
			}
		}
		return str1;
	}

	public static String timeStringAll(long paramLong) {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(
				paramLong));
	}

	public static String timeStringBySecond(long paramLong) {
		return new SimpleDateFormat("MM-dd HH:mm:ss").format(new Date(
				1000L * paramLong));
	}

	public static abstract interface IpValidListener {
		public abstract void ipInvalid();

		public abstract void ipValid();
	}

	public static abstract interface cleanCacheListener {
		public abstract void onComplete();

		public abstract void onErr();

		public abstract void onNull();

		public abstract void onStar();
	}

	public static abstract interface hasDownloadFileListener {
		public abstract void onComplete(File paramFile);

		public abstract void onErr();

		public abstract void onNull();
	}
}